package hello.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 *
 * swagger配置
 */
@Configuration

// 使用swagger
@EnableSwagger2
public class SwaggerConfig {


    @Value("${swagger.title}")
    private String title;

    @Bean
    // 实例swagger的对象
    public Docket createRestApi() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        return docket.apiInfo(apiInfo())
                .select()
                // 指定使用@ApiOperation注解的包
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    // swagger-ui页面的头部信息
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(title)
                .version("1.0")
                .contact(new Contact("tottimctj", "https://www.baidu.com", "267101292@qq.com"))
                .build();
    }
}
